home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr13 / tstse13.zip / DEJUSTIF.S < prev    next >
Text File  |  1994-11-26  |  4KB  |  141 lines

  1. /* Cancel the effects of right-justification for SemWare's TSE
  2.    editor V2.0. To make this SAL macro operational, invoke the main
  3.    menu (F10), choose "Macro", choose "Compile" and press Enter at
  4.    "Execute Macro".
  5.  
  6. ..................................................................
  7. Prof. Timo Salmi      Co-moderator of comp.archives.msdos.announce
  8. Moderating at garbo.uwasa.fi anonymous FTP archives  193.166.120.5
  9. Faculty of Accounting & Industrial Management; University of Vaasa
  10. Internet: ts@uwasa.fi   BBS +(358)-61-3170972; FIN-65101,  Finland
  11. */
  12.  
  13. // The contents of a simple help, tied later to the CtrlAlt-H key
  14. helpdef tHelpData
  15.   title = "DEJUSTIF.S HELP"       // The help's caption
  16.   x = 10                          // Location
  17.   y = 3
  18.   // The actual help text
  19.   " Prof. Timo Salmi's dejustify a right margin "
  20.   ""
  21.   " The justify procedure in the Potpourri collection "
  22.   " justifies a paragraph based on the right margin. "
  23.   " The dejustify procedure in this macro collection "
  24.   " can be used to cancel the effect. "
  25.   ""
  26.   " You can use <F11> to invoke the command menu "
  27.   " after first exiting this help. "
  28.   ""
  29.   " Last updated Sat 26-November-1994 20:04:17 "
  30. end  /* tHelpData */
  31.  
  32. /* Please first get mWrapPara() from tse.ui file which comes with
  33.    TSE distribution */
  34. proc mWrapPara()
  35.   Warn ("Plug mWrapPara() from tse.ui into JUSTIFY.S before first use ")
  36. end mWrapPara
  37.  
  38. /* These procedures are used to weed out the superfluous spaces.
  39.    That is to dejustify right adjusted text */
  40.  
  41. // Auxiliary
  42. proc timoGotoParagraphBegin()
  43.   BegLine()
  44.   if PosFirstNonWhite() > 0        // If we are not on an "empty" line
  45.     repeat
  46.       Up()
  47.     until PosFirstNonWhite() == 0  OR CurrLine() == 1
  48.     if PosFirstNonWhite() == 0
  49.       Down()
  50.     endif
  51.   endif
  52.   if PosFirstNonWhite() > 0
  53.     GotoColumn(PosFirstNonWhite())
  54.   endif
  55. end
  56.  
  57. // Auxiliary
  58. proc timoGotoParagraphEnd(integer backtrack)
  59.   BegLine()
  60.   if PosFirstNonWhite() > 0
  61.     repeat
  62.       Down()
  63.     until PosFirstNonWhite() == 0 OR CurrLine() >= NumLines()
  64.     if CurrLine() == NumLines()
  65.       EndLine()
  66.     else
  67.       if backtrack == 1
  68.         PrevChar()
  69.       endif
  70.     endif
  71.   endif
  72. end
  73.  
  74. // Auxiliary
  75. proc timoMakeBlock()
  76.   PushPosition()
  77.   UnmarkBlock()
  78.   timoGotoParagraphBegin()
  79.   MarkChar()
  80.   timoGotoParagraphEnd(1)
  81.   MarkChar()
  82.   PopPosition()
  83. end
  84.  
  85. proc timoCondense()
  86.   integer i = 0
  87.   PushPosition()
  88.   mWrapPara()
  89.   PopPosition()
  90.   //
  91.   repeat
  92.     i = i + 1
  93.     timoMakeBlock()
  94.     if isBlockMarked() AND isBlockInCurrFile()
  95.       lReplace("  "," ","ln")
  96.     endif
  97.   until i == 10
  98.   UnmarkBlock()
  99.   timoGotoParagraphEnd(0)
  100.   while PosFirstNonWhite() == 0 AND CurrLine() < NumLines()
  101.     Down()
  102.   endwhile
  103.   ScrollToRow(3*Query(WindowRows)/4)
  104. end timoCondense
  105.  
  106. // New keys and menus **************************************************
  107. forward Menu timoCondenseMenu()
  108. forward proc tDisableNewKeys()
  109.  
  110. // Add the new key definitions
  111. keydef new_keys
  112.   <CtrlAlt 5>      timoCondense()
  113.   <CtrlAlt 0>      tDisableNewKeys()
  114.   <CtrlAlt H>      QuickHelp(tHelpData)
  115.   <F11>            timoCondenseMenu()
  116. end
  117.  
  118. // Disabling the new extra keys ***************************************
  119. proc tDisableNewKeys()
  120.   if YesNo("Disable the extra keys:") == 1 Disable(new_keys) endif
  121. end
  122.  
  123. // The condense menu ******************************************************
  124. Menu timoCondenseMenu()
  125.   Title = "Timo's dejustify menu"
  126.   Width = 19
  127.   x = 40
  128.   y = 3
  129.   history
  130.   "&Dejustify right margin <CtrlAlt 5>"   , timoCondense()
  131.   "",,Divide
  132.   "Disable &new keys       <CtrlAlt 0>"   , tDisableNewKeys()
  133.   "&Help                   <CtrlAlt H>"   , QuickHelp(tHelpData)
  134.   "This &Menu              <F11>"
  135. end  /* timoCondenseMenu */
  136.  
  137. proc Main()
  138.   Enable (new_keys)
  139.   timoCondenseMenu()
  140. end
  141.